<template>
	<w-container id='colection' :loading='loading' class="bg-color-pageBg">
		<w-navbar :placeholder="false" navType="goods" :title='pageTitle' :bgColor="bgColor" :opacity="opacity"
			:leftIconSize="32" :leftIcon="opacity>0.8?'arrow-left-back':'arrow-left-back'"
			:titleStyle="{color:opacity>0.8?'#fff':'#fff'}" :product="product" :projectMainImage="projectMainImage">
		</w-navbar>
		<!-- 主图部分 -->
		<w-product-details-card :product='product' :info='info'>
			<view v-if="darwIsOpen" slot="right">
				<view style="border: 1rpx solid #fff;" class="pa-4 font-color-white br-4 font-size-12">
					{{typeList[signUpStatus].title}}
				</view>
			</view>
		</w-product-details-card>
		<w-product-alldraw v-if="darwIsOpen" :info="codeInfo" :product="product"></w-product-alldraw>
		<view style="background-color: #1f1f1f;">
			<!-- 藏品故事 -->
			<w-product-introduce :product='product'></w-product-introduce>
			<u-gap height="100rpx"></u-gap>
			<!-- 商品介绍 -->
			<w-product-detail :product="product"></w-product-detail>
		</view>
		<!-- 创作者信息及品牌方信息 --> 
		<w-product-builder :showYYZ="false" :product='product'></w-product-builder>
		<!-- 商品信息 -->
		<!-- <w-product-info-list class='mt-12' :info='info'></w-product-info-list> -->

		<!-- 购买须知 -->
		<w-product-buy-need class='mt-12' :product='product'></w-product-buy-need>
		<!-- 版权 -->
		<!-- <w-copyright></w-copyright> -->
		<u-gap height="100"></u-gap>
		<w-product-action v-if="!darwIsOpen" :product='product'></w-product-action>
		<z-draw-actionV2 v-else :product='product' :invitFriend="invitFriend" :codeInfo="codeInfo"></z-draw-actionV2>
	</w-container>
</template>

<script>
	import {
		getCollectionDetails
	} from '@/api/collection/index.js'
	import product from '@/mixins/product.js';
	import productMixin from '@/mixins/product.js'
	import opacityMixin from '@/mixins/opacityNav.js'
	import drawMixin from '@/mixins/draw.js'
	import {
		drawMycode
	} from '@/api/draw/index.js'
	export default {
		mixins: [productMixin, opacityMixin, drawMixin],
		data() {
			return {
				loading: true,
				id: null,
				batch_id: null,
				product: {
					goods_type: 2,
					publisher: {},
					series: {}
				},
				invitFriend: 0,
				codeInfo: {
					my_code: []
				},
				typeList: {
					1: {
						title: '未开始',
						color: '#B67930'
					},
					2: {
						title: '抽签中',
						color: '#FF303B'
					},
					// 2:{
					// 	title:'付款中',
					// 	color:'#25406F'
					// },
					3: {
						title: '已结束',
						color: '#999999'
					},
				}
			};
		},
		computed: {
			info() {
				return {
					series_name: this.product.series?.name
				}
			}
		},
		mounted() {
			uni.$on('signUpChange', () => {
				this.getDrawMycode()
			})
		},
		onLoad({
			id,
			batch_id,
			invitFriend
		}) {
			console.log(id, batch_id, invitFriend);
			this.id = id;
			this.batch_id = batch_id;
			if (invitFriend) {
				this.invitFriend = invitFriend
				uni.setStorageSync('invitFriend', this.invitFriend)
			}
			if (uni.getStorageSync('invitFriend')) this.invitFriend = uni.getStorageSync('invitFriend')
			this.getDetails();
		},
		onPullDownRefresh() {
			this.getDetails()
		},
		methods: {
			async getDetails() {
				this.loading = true
				try {
					let res = await getCollectionDetails(this.id, this.batch_id)
					this.product = res.data;
					this.product.goods_type = 2
					if (this.product.batch) {
						this.product.batch_id = this.product.batch.id
					}
					if (uni.getStorageSync('token')) this.getDrawMycode()
				} catch (e) {
					console.log(e);
					setTimeout(() => {
						this.backPage()
					}, 1500)
				} finally {
					uni.stopPullDownRefresh()
					this.loading = false;
				}
			},
			targetLike() {
				this.$set(this.product, 'is_like', !this.product.is_like)
			},
			//获取我的抽签码/结果
			getDrawMycode() {
				let data = {
					goods_id: this.drawBase.id,
					goods_type: this.product.goods_type
				}
				drawMycode(data).then(res => {
					this.codeInfo = res.data
					// console.log(this.codeInfo)
				}).catch(err => {})
			},
		}
	}
</script>

<style lang="scss" scoped>
	#colection {
		padding-bottom: calc(env(safe-area-inset-bottom) + 120rpx);
	}
</style>